package com.atguigu.springbootdemo.customer.mapper;

import com.atguigu.springbootdemo.customer.bean.Customer;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * ClassName: CustomerMapper
 * Package: com.atguigu.springbootdemo.mapper
 * Description:
 *
 * @Author:
 * @Create: 2024/3/13 09:30
 * @Version: 1.0
 */
@Mapper
@DS("test")
public interface CustomerMapper extends BaseMapper<Customer> {

    /*
    Mybatis  占位符
    #{}: 用的多， 比较智能 ， 自动分析参数类型，如果是字符串类型， 会自动添加''  ， 能解析对象的属性
    ${}: 用的少， 原样显示 , 一般用于已经拼接好的SQL,直接原样获取即可。
     */
    @Select("select id, username from customer where id = #{id}")
    Customer selectCustomerById(Integer id);

    @Select("select * from customer  ")
    List<Customer> getCustomerList();

    @Insert("insert into customer (username, age) values (#{c.username},#{c.age})")
    void insertCustomer(@Param("c") Customer customer);

    @Update("update customer set username = #{username} , age = #{age} where id = #{id} ")
    void updateCustomerById(Customer customer);

    @Delete("delete from customer where id = #{id}")
    void deleteCustomerById(Integer id ) ;


    // 动态sql
    @Select("${sql}")
    List<Customer> selectCustomersByUsernameAndAge(String sql);
}
